//
//  UIScrollView+ZKChain.m
//  ChainFun
//
//  Created by 洪绵卫 on 2022/1/10.
//

#import "UIScrollView+ZKChain.h"

@implementation UIScrollView (ZKChain)

+ (UIScrollView * _Nonnull (^)(void))zk_allocInit{
    return ^{
         UIScrollView *v = [[UIScrollView alloc]init];
        return v;
    };
}

+ (UIScrollView * _Nonnull (^)(CGRect))zk_allocInitWithFrame{
    return ^(CGRect rect){
        UIScrollView * v = [[UIScrollView alloc]initWithFrame:rect];
        return v;
    };
}

- (UIScrollView * _Nonnull (^)(CGRect))zk_frame{
    return ^(CGRect rect){
        self.frame = rect;
        return self;
    };
}

- (UIScrollView * _Nonnull (^)(UIColor * _Nonnull))zk_backgroundColor{
    return ^(UIColor *color){
        self.backgroundColor = color;
        return self;
    };
}

- (UIScrollView * _Nonnull (^)(UIView * _Nonnull))zk_addToSuperView{
    return ^(UIView *view){
        [view addSubview:self];
        return self;
    };
}

- (UIScrollView * _Nonnull (^)(BOOL))zk_userInteractionEnabled{
    return ^(BOOL isUserInteractionEnabled){
        self.userInteractionEnabled = isUserInteractionEnabled;
        return self;
    };
}

- (UIScrollView * _Nonnull (^)(NSInteger))zk_tag{
    return ^(NSInteger tag){
        self.tag = tag;
        return self;
    };
}

- (UIScrollView * _Nonnull (^)(CGRect))zk_bounds;{
    return ^(CGRect rect){
        self.bounds = rect;
        return self;
    };
}

- (UIScrollView * _Nonnull (^)(CGPoint))zk_center{
    return ^(CGPoint point){
        self.center = point;
        return self;
    };
}

- (UIScrollView * _Nonnull (^)(CGFloat))zk_alpha{
    return ^(CGFloat value){
        self.alpha = value;
        return self;
    };
}

- (UIScrollView * _Nonnull (^)(BOOL))zk_hidden{
    return ^(BOOL isHidden){
        self.hidden = isHidden;
        return self;
    };
}

- (UIScrollView * _Nonnull (^)(UIColor * _Nonnull))zk_tintColor{
    return ^(UIColor *col){
        self.tintColor = col;
        return self;
    };
}

#pragma mark UIScrollView 的一些属性
- (UIScrollView * _Nonnull (^)(id<UIScrollViewDelegate> _Nullable))zk_delegate{
    return ^(id<UIScrollViewDelegate> _Nullable delegate){
        self.delegate = delegate;
        return self;
    };
}

- (UIScrollView * _Nonnull (^)(CGPoint))zk_contentOffset{
    return ^(CGPoint offset){
        self.contentOffset = offset;
        return self;
    };
}

/// 内容大小
- (UIScrollView * _Nonnull (^)(CGSize))zk_contentSize{
    return ^(CGSize size){
        self.contentSize = size;
        return self;
    };
}

/// 内容边距
- (UIScrollView * _Nonnull (^)(UIEdgeInsets))zk_contentInset{
    return ^(UIEdgeInsets contentInset){
        self.contentInset = contentInset;
        return self;
    };
}

- (UIScrollView * _Nonnull (^)(UIScrollViewContentInsetAdjustmentBehavior))zk_contentInsetAdjustmentBehavior API_AVAILABLE(ios(11.0)){
    return ^(UIScrollViewContentInsetAdjustmentBehavior inset){
        self.contentInsetAdjustmentBehavior = inset;
        return self;
    };
}

- (UIScrollView * _Nonnull (^)(BOOL))zk_automaticallyAdjustsScrollIndicatorInsets API_AVAILABLE(ios(13.0)){
    return ^(BOOL isIndicatorInsets){
        self.automaticallyAdjustsScrollIndicatorInsets = isIndicatorInsets;
        return self;
    };
}

- (UIScrollView * _Nonnull (^)(BOOL))zk_bounces{
    return ^(BOOL value){
        self.bounces = value;
        return self;
    };
}

- (UIScrollView * _Nonnull (^)(BOOL))zk_alwaysBounceVertical{
    return ^(BOOL value){
        self.alwaysBounceVertical = value;
        return self;
    };
}

- (UIScrollView * _Nonnull (^)(BOOL))zk_alwaysBounceHorizontal{
    return ^(BOOL value){
        self.alwaysBounceHorizontal = value;
        return self;
    };
}

- (UIScrollView * _Nonnull (^)(BOOL))zk_pagingEnabled{
    return ^(BOOL value){
        self.pagingEnabled = value;
        return self;
    };
}

- (UIScrollView * _Nonnull (^)(BOOL))zk_scrollEnabled{
    return ^(BOOL value){
        self.scrollEnabled = value;
        return self;
    };
}

- (UIScrollView * _Nonnull (^)(BOOL))zk_showsVerticalScrollIndicator{
    return ^(BOOL value){
        self.showsVerticalScrollIndicator = value;
        return self;
    };
}

- (UIScrollView * _Nonnull (^)(BOOL))zk_showsHorizontalScrollIndicator{
    return ^(BOOL value){
        self.showsHorizontalScrollIndicator = value;
        return self;
    };
}

- (UIScrollView * _Nonnull (^)(UIScrollViewIndicatorStyle))zk_indicatorStyle{
    return ^(UIScrollViewIndicatorStyle style){
        self.indicatorStyle = style;
        return self;
    };
}

- (UIScrollView * _Nonnull (^)(UIEdgeInsets))zk_verticalScrollIndicatorInsets API_AVAILABLE(ios(11.1), tvos(11.1)){
    return ^(UIEdgeInsets value){
        self.verticalScrollIndicatorInsets = value;
        return self;
    };
}

- (UIScrollView * _Nonnull (^)(UIEdgeInsets))zk_horizontalScrollIndicatorInsets API_AVAILABLE(ios(11.1), tvos(11.1)){
    return ^(UIEdgeInsets value){
        self.horizontalScrollIndicatorInsets = value;
        return self;
    };
}

- (UIScrollView * _Nonnull (^)(UIEdgeInsets))zk_scrollIndicatorInsets{
    return ^(UIEdgeInsets value){
        self.scrollIndicatorInsets = value;
        return self;
    };
}

- (UIScrollView * _Nonnull (^)(CGFloat))zk_minimumZoomScale{
    return ^(CGFloat value){
        self.minimumZoomScale = value;
        return self;
    };
}

- (UIScrollView * _Nonnull (^)(CGFloat))zk_maximumZoomScale{
    return ^(CGFloat value){
        self.maximumZoomScale = value;
        return self;
    };
}

- (UIScrollView * _Nonnull (^)(CGFloat))zk_zoomScale{
    return ^(CGFloat value){
        self.zoomScale = value;
        return self;
    };
}

- (UIScrollView * _Nonnull (^)(BOOL))zk_bouncesZoom{
    return ^(BOOL value){
        self.bouncesZoom = value;
        return self;
    };
}

- (UIScrollView * _Nonnull (^)(BOOL))zk_scrollsToTop{
    return ^(BOOL value){
        self.scrollsToTop = value;
        return self;
    };
}

- (UIScrollView * _Nonnull (^)(UIScrollViewKeyboardDismissMode))zk_keyboardDismissMode{
    return ^(UIScrollViewKeyboardDismissMode mode){
        self.keyboardDismissMode = mode;
        return self;
    };
}

- (UIScrollView * _Nonnull (^)(UIRefreshControl * _Nullable))zk_refreshControl API_AVAILABLE(ios(10.0)){
    return ^(UIRefreshControl *refreshControl){
        self.refreshControl = refreshControl;
        return self;
    };
}

#pragma mark UIScrollView 的一些方法
/// 实际为 - (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated
- (UIScrollView * _Nonnull (^)(CGPoint,BOOL))zk_setContentOffsetWithAnimated{
    return ^(CGPoint offset,BOOL isAnimated){
        [self setContentOffset:offset animated:isAnimated];
        return self;
    };
}

- (UIScrollView * _Nonnull (^)(CGRect,BOOL))zk_scrollRectToVisibleWithAnimated{
    return ^(CGRect rect,BOOL isAnimated){
        [self scrollRectToVisible:rect animated:isAnimated];
        return self;
    };
}
@end
